﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class finance : System.Web.UI.Page
    {
        public int PageIndex
        {
            get
            {
                return int.Parse(ViewState["pageIndex"].ToString());
            }
            set
            {
                ViewState["pageIndex"] = value;
            }
        }
        public int PageCount
        {
            get
            {
                return int.Parse(ViewState["PageCount"].ToString());
            }
            set
            {
                ViewState["PageCount"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                if (Session["Users"].ToString() != "finance" && Session["Users"].ToString() != "admin")
                {
                    Response.Write("<script>alert('你的权限不足！');location.href='Home.aspx';</script>");
                }
                
                int rowsCount = new FundsBLL().Select("Funds").Rows.Count; //行数
                PageCount = (rowsCount / 5);
                if (rowsCount % 5 != 0)
                {
                    PageCount++;
                }
                PageIndex = 1;
                GoPage();
            }
        }
        public void GoPage()
        {
            string TableName = "Funds";
            this.rpMoney.DataSource = new FundsBLL().FY(TableName, PageIndex);
            this.rpMoney.DataBind();
        }

        protected void rpMoney_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                string TableName = "Funds";
                int id = int.Parse(e.CommandArgument.ToString());
                if (new FundsBLL().Del(TableName, id))
                {
                    GoPage();
                }

            }
        }

        protected void sel_Click(object sender, EventArgs e)
        {
            string TableName = "Funds";
            string mz = this.sev.Value;
            this.rpMoney.DataSource = new financeBLL().SelectNo(TableName, mz);
            this.rpMoney.DataBind();
        }

        protected void btnPageFirst_Click(object sender, EventArgs e)
        {
            PageIndex = 1;
            GoPage();
        }

        protected void btnPagePre_Click(object sender, EventArgs e)
        {
            if (PageIndex > 1)
            {
                PageIndex--;

            }

            GoPage();
        }

        protected void btnPageNext_Click(object sender, EventArgs e)
        {
            if (PageIndex < PageCount)
            {
                PageIndex++;
            }
            GoPage();
        }

        protected void btnPageLast_Click(object sender, EventArgs e)
        {
            PageIndex = PageCount;
            GoPage();
        }
    }
}